import React, { Component } from "react";
import PubSub from "pubsub-js";
import axios from "axios";
export default class index extends Component {
  seachRes = () => {
    // const { updateItems } = this.props;
    const { value } = this.keyWordEle;
    PubSub.publish("UPDATE", { isFirst: false, isLoading: true });
    // updateItems({ isFirst: false, isLoading: true });
    // http://localhost:3000/api/search
    axios.get(`/api/search/users332?q=${value}`).then(
      (res) => {
        const {
          data: { items },
        } = res;
        PubSub.publish("UPDATE", { items, isLoading: false });
        // updateItems({ items, isLoading: false });
      },
      (err) => {
        PubSub.publish("UPDATE", { err: err.message, isLoading: false });
        // updateItems({ err: err.message, isLoading: false });
      }
    );
  };
  render() {
    return (
      <section className="jumbotron">
        <h3 className="jumbotron-heading">搜索相关用户</h3>
        <div>
          <input
            ref={(c) => (this.keyWordEle = c)}
            type="text"
            placeholder="输入关键字"
          />
          &nbsp;<button onClick={this.seachRes}>搜索</button>
        </div>
      </section>
    );
  }
}
